package com.housediyadmin.service
{
<<<<<<< .mine

=======
>>>>>>> .r59
	import com.housediyadmin.events.goodsEvents.AddGoodsEvent;

	import com.housediyadmin.command.fittingCommand.GetFittingByGoodsIDCmd;

	import com.housediyadmin.events.goodsEvents.GetAllGoodsEvent;
	import com.housediyadmin.events.goodsEvents.GetGoodsByBrandIDEvent;
	import com.housediyadmin.events.goodsEvents.GetGoodsByDictFlagEvent;
	import com.housediyadmin.events.goodsEvents.GetGoodsByFittingIDEvent;
	import com.housediyadmin.events.goodsEvents.GetGoodsByNewsIDEvent;
	import com.housediyadmin.events.goodsEvents.GetGoodsBySalesIDEvent;
	import com.housediyadmin.events.goodsEvents.GetGoodsByTypeIDEvent;
	import com.housediyadmin.events.treeEvents.GetGoodsTreeEvent;
	import com.housediyadmin.vo.Goods;
	
	import mx.collections.ArrayCollection;
	import mx.collections.XMLListCollection;
	import mx.controls.Alert;
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import org.robotlegs.mvcs.Actor;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class GoodsRemoteObjectService extends Actor
	{
		public var  goodsRemoteObject:RemoteObject;
		
		public function GoodsRemoteObjectService()
		{
			super();
			
			var amfChannel:Array = [new AMFChannel(null, "http://localhost/housediyadmin/Gateway.aspx")];
			//var amfChannel:Array = [new AMFChannel(null, "http://10.60.1.120/HouseDiyAdmin/Gateway.aspx")];
			var channelSet:ChannelSet = new ChannelSet();
			channelSet.channels = amfChannel;
			
			goodsRemoteObject = new RemoteObject("fluorine");
			goodsRemoteObject.source = "HouseDiyService.HouseDiyAction";
			goodsRemoteObject.showBusyCursor = true;
			goodsRemoteObject.channelSet = channelSet;
			
			//GoodsTree相关
			/*goodsRemoteObject.getOperation("xmlGetGoodsLevel").addEventListener(ResultEvent.RESULT, getGoodsTreeResultHandler);
			goodsRemoteObject.getOperation("xmlGetGoodsLevel").addEventListener(FaultEvent.FAULT, faultHandler);
								
			goodsRemoteObject.getOperation("addGoodsType").addEventListener(ResultEvent.RESULT, addGoodsLevelHandler);
			goodsRemoteObject.getOperation("addGoodsType").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("deleteGoodsType").addEventListener(ResultEvent.RESULT, deleteGoodsLevelHandler);
			goodsRemoteObject.getOperation("deleteGoodsType").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("editGoodsType").addEventListener(ResultEvent.RESULT, editGoodsLevelHandler);
			goodsRemoteObject.getOperation("editGoodsType").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("haveGoodsByTypeID").addEventListener(ResultEvent.RESULT, hasGoodsByTypeIdHandler);
			goodsRemoteObject.getOperation("haveGoodsByTypeID").addEventListener(FaultEvent.FAULT, faultHandler);
			
			
			//Goods相关
			goodsRemoteObject.getOperation("getGoodsByDict").addEventListener(ResultEvent.RESULT, getGoodsByIdResultHandler);
			goodsRemoteObject.getOperation("getGoodsByDict").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("getGoodsByTypeIDs").addEventListener(ResultEvent.RESULT, getGoodsByIdResultHandler);
			goodsRemoteObject.getOperation("getGoodsByTypeIDs").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("deleteGoodsByIDs").addEventListener(ResultEvent.RESULT, deleteGoodsResult);
			goodsRemoteObject.getOperation("deleteGoodsByIDs").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("addAGood").addEventListener(ResultEvent.RESULT, addGoodsResult);
			goodsRemoteObject.getOperation("addAGood").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("editAGood").addEventListener(ResultEvent.RESULT, editGoodsResult);
			goodsRemoteObject.getOperation("editAGood").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("getGoodsNameByBrandID").addEventListener(ResultEvent.RESULT, getGoodsByBrandIdResult);
			goodsRemoteObject.getOperation("getGoodsNameByBrandID").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("getGoodsNameBySalesID").addEventListener(ResultEvent.RESULT, getGoodsBySalesIdResult);
			goodsRemoteObject.getOperation("getGoodsNameBySalesID").addEventListener(FaultEvent.FAULT, faultHandler);
			
			goodsRemoteObject.getOperation("getGoodsNameByNewsID").addEventListener(ResultEvent.RESULT, getGoodsByNewsIdResult);
			goodsRemoteObject.getOperation("getGoodsNameByNewsID").addEventListener(FaultEvent.FAULT, faultHandler);*/
			
			goodsRemoteObject.getOperation("getGoodsByDictFlag").addEventListener(ResultEvent.RESULT, getGoodsByDictFlagHandler);
		    goodsRemoteObject.getOperation("getGoodsByDictFlag").addEventListener(FaultEvent.FAULT, faultHandler);

			
			goodsRemoteObject.getOperation("addAGoodsWithFitting").addEventListener(ResultEvent.RESULT, addGoodsResult);
			goodsRemoteObject.getOperation("addAGoodsWithFitting").addEventListener(FaultEvent.FAULT, faultHandler);

			
			goodsRemoteObject.getOperation("getGoodsByFittingID").addEventListener(ResultEvent.RESULT, getGoodsByFittingIdResult);
			goodsRemoteObject.getOperation("getGoodsByFittingID").addEventListener(FaultEvent.FAULT, faultHandler);

		}
		
		public function getGoodsByFittingId(fittingId:int):void
		{
			goodsRemoteObject.getGoodsByFittingID(fittingId);
		}
		
		public function getGoodsByDictAndFlag(dict:int, flag:int):void
		{
			goodsRemoteObject.getGoodsByDictFlag(dict, flag);
		}
		
		public function addGoods(goods:Goods, fittingIds:Array):void
		{
			goodsRemoteObject.addAGoodsWithFitting(goods, fittingIds);
		}
		
		public function getGoodsByDict(dictName:String):void
		{
			goodsRemoteObject.getGoodsByDict(dictName);
		}
		
		public function getGoodsTree():void
		{
			goodsRemoteObject.xmlGetGoodsLevel();
		}
		
		public function getGoodsById(idArray:Array):void
		{
			goodsRemoteObject.getGoodsByTypeIDs(idArray);
		}
		
		public function addGoodsLevel(typeName:String, typeParentId:int, typeLevel:int):void
		{
			goodsRemoteObject.addGoodsType(typeName, typeParentId, typeLevel);
		}
		
		public function hasGoodsByTypeId(typeId:int):void
		{
			goodsRemoteObject.haveGoodsByTypeID(typeId);
		}
		
		public function deleteGoodsLevel(typeId:int):void
		{
			goodsRemoteObject.deleteGoodsType(typeId);
		}
		
		public function editGoodsLevel(typeId:int, typeName:String):void
		{
			goodsRemoteObject.editGoodsType(typeId, typeName);
		}
		
		public function deleteGoodsByIds(goodsIds:Array, typeIds:Array):void
		{
			goodsRemoteObject.deleteGoodsByIDs(goodsIds, typeIds);
		}
		
		
		public function editGoods(goods:Goods, typeIds:Array, fittingIds:Array):void
		{
			goodsRemoteObject.editAGood(goods, typeIds, fittingIds);
		}
		
		public function getGoodsByBrandId(brandId:int):void
		{
			goodsRemoteObject.getGoodsNameByBrandID(brandId);
		}
		
		public function getGoodsBySalesId(salesId:int):void
		{
			goodsRemoteObject.getGoodsNameBySalesID(salesId); 
		}
		
		public function getGoodsByNewsId(newsId:int):void
		{
			goodsRemoteObject.getGoodsNameByNewsID(newsId); 
		}
		
		private function getGoodsByFittingIdResult(event:ResultEvent):void
		{
			dispatch(new GetGoodsByFittingIDEvent(GetGoodsByFittingIDEvent.UPDATE_GOODS_FITTING, 0, event.result as ArrayCollection));
		}
		
		private function getGoodsByDictFlagHandler(event:ResultEvent):void
		{
			dispatch(new GetGoodsByDictFlagEvent(GetGoodsByDictFlagEvent.UPDATE_RELATEGOODS, 0, 0, event.result as ArrayCollection));
		}
		
		private function getGoodsTreeResultHandler(event:ResultEvent):void
		{
			dispatch(new GetGoodsTreeEvent(GetGoodsTreeEvent.UPDATE_GOODS_TREE, new XMLListCollection((event.result as XML).children())));
		}
		
		private function getGoodsByIdResultHandler(event:ResultEvent):void
		{
/*			dispatch(new GetGoodsByTypeIDEvent(GetGoodsByTypeIDEvent.UPDATE_GOODS_MODEL, null, event.result as ArrayCollection));
*/		    dispatch(new GetAllGoodsEvent(GetAllGoodsEvent.UPDATE_GOODS_MODEL, null, event.result as ArrayCollection));
		}
		
		private function addGoodsLevelHandler(event:ResultEvent):void
		{
			dispatch(new GetGoodsTreeEvent(GetGoodsTreeEvent.UPDATE_GOODS_TREE, new XMLListCollection((event.result as XML).children())));
		}
		
		private function deleteGoodsLevelHandler(event:ResultEvent):void
		{
			dispatch(new GetGoodsTreeEvent(GetGoodsTreeEvent.UPDATE_GOODS_TREE, new XMLListCollection((event.result as XML).children())));
		}
		
		private function editGoodsLevelHandler(event:ResultEvent):void
		{
			dispatch(new GetGoodsTreeEvent(GetGoodsTreeEvent.UPDATE_GOODS_TREE, new XMLListCollection((event.result as XML).children())));
		}
		
		private function hasGoodsByTypeIdHandler(event:ResultEvent):void
		{
			
		}
		
		private function deleteGoodsResult(event:ResultEvent):void
		{
			dispatch(new GetGoodsByTypeIDEvent(GetGoodsByTypeIDEvent.UPDATE_GOODS_MODEL, null, event.result as ArrayCollection));
		}
		
		private function addGoodsResult(event:ResultEvent):void
		{
			dispatch(new AddGoodsEvent(AddGoodsEvent.UPDATE,event.result as Goods, null));
		}
		
		private function editGoodsResult(event:ResultEvent):void
		{
			dispatch(new GetGoodsByTypeIDEvent(GetGoodsByTypeIDEvent.UPDATE_GOODS_MODEL, null, event.result as ArrayCollection));
		}
		
		private function getGoodsByBrandIdResult(event:ResultEvent):void
		{
			dispatch(new GetGoodsByBrandIDEvent(GetGoodsByBrandIDEvent.UPDATE_GOODS_BRAND, 0, event.result as ArrayCollection));
		}
		
		private function getGoodsBySalesIdResult(event:ResultEvent):void
		{
			dispatch(new GetGoodsBySalesIDEvent(GetGoodsBySalesIDEvent.UPDATE_GOODS_SALES, 0, event.result as ArrayCollection));
		}
		
		private function getGoodsByNewsIdResult(event:ResultEvent):void
		{
			dispatch(new GetGoodsByNewsIDEvent(GetGoodsByNewsIDEvent.UPDATE_GOODS_NEWS, 0, event.result as ArrayCollection));
		}
		
		private function faultHandler(event:FaultEvent):void
		{
			Alert.show(" fault :" + event.toString());
		}
	}
}